package leetcode;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.PriorityQueue;

public class PriorityQueueTest {

	public static void main(String[] args) {
		
	}
	
	public static List<Integer> getMostKNumbers(int[] nums, int k) {
		List<Integer> list = new ArrayList<>();
		PriorityQueue<Integer> pq = new PriorityQueue<>(k, new Comparator<Integer>() {

			@Override
			public int compare(Integer o1, Integer o2) {
				return o2.compareTo(o1);
			}
			
		});
		for (int i = 0; i < nums.length; i++) {
			if (pq.size() < k) {
				pq.offer(nums[i]);
			} else {
				if (nums[i] < pq.peek()) {
					Integer temp = pq.poll();
					temp = null;
					pq.offer(nums[i]);
				}
			}
		}
		for (Integer i : pq) {
			list.add(i);
		}
		return list;
	}

}
